new Vue({
    el: "#main",
    data: {
        email: "",
        password: "",
        code: ""
    },
    methods: {
        login: function () {
            axios.post("http://localhost:8080/login", {
                email: this.email,
                password: this.password,
                code: this.code
            }).then(response => {
                if (response.data.code == 200) {
                    localStorage.setItem('userEmail', this.email);
                    localStorage.setItem('userId', response.data.data.userId);
                    localStorage.setItem("nickName", response.data.data.nickname || "用户" + Math.random() * 10000000000000);
                    location.href = "index.html";
                }
            }).catch(error => { // 添加错误处理
                console.error("登录请求失败:", error);
            });
        },
        sendCode: function () {
            if (this.email.trim() != "") {
                axios.get("http://localhost:8080/sendCode", {
                    params: {
                        "email": this.email
                    }
                }).then(response => {
                    console.log(response.data);
                }).catch(error => {
                    console.error("发送验证码失败:", error);
                })
            }
        }
    }
})